package com.zhang.crawler.crawler.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description
 * @date 2019/5/9
 */
public class StringUtils {

    /**
     * inputStream转换为字符串
     * @param inpurtStream
     * @return
     */
    public static String inputStream2String(InputStream inpurtStream){
        try{
            if(inpurtStream!=null){
                ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
                byte[] buff = new byte[100];
                int rc = 0;
                while ((rc = inpurtStream.read(buff, 0, 100)) > 0) {
                    swapStream.write(buff, 0, rc);
                }
                byte[] dataByteArr = swapStream.toByteArray();
                return new String(dataByteArr);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}
